*****************************************************************
***                 Scripts AkelPad plugin v12.2              ***
*****************************************************************

2012 Shengalts Aleksander aka Instructor (Shengalts@mail.ru)


*** Description ***

Scripts plugin is based on the Windows Scripting Host (WSH) engine,
so you can use various Windows Component Object Model (COM)
objects. For example, you can perform regular expression searches
using the RegExp object, manipulate files using the FileSystemObject
object, create a short-cut, manipulate the Windows Registry using
the WshShell object, or work with networking functions using the
WshNetwork object. Additionally, you can create and execute a
script that utilizes an external application that supports Automation
(such as Word and Excel). Plugin code is based on Jeff Glatt's "COM in C".


*** Included scripts ***

SearchReplace.js      -search/replace using regular expressions.
SpellCheck.js         -spell check using Microsoft Word.
LinesFilter.js        -filter lines using regular expressions.
Calculator.js         -text calculator.
EvalCmd.js            -evaluates an expression passed through command line.
InsertDate.js         -insert time and date in specified format.
InsertFile.js         -insert contents of a file.
RenameFile.js         -rename current editing file.
Keyboard.js           -convert keyboard layout or transliterate text.
ColumnCounter.js      -column selection counter.
Test.js               -test script on JScript.
Test.vbs              -test script on VBScript.


*** Functions ***

Scripts::Main
Main dialog.


*** External call ***

Call("Scripts::Main", 1, "SCRIPT", "ARGUMENTS")
  Parameters:
    1
      Execute script. If "", then last processed script used.
    "SCRIPT"
      Script file.
    "ARGUMENTS"
      Argumets (default is "").
  Examples:
    Call("Scripts::Main", 1, "InsertDate.js")
    Call("Scripts::Main", 1, "InsertDate.js", `"dd MMMM yyyy"`)

Call("Scripts::Main", 2, "SCRIPT", "ARGUMENTS")
  Same as previous, but wait for script completion.

Call("Scripts::Main", 3, "SCRIPT")
  Parameters:
    3
      Open script for editing.
    "SCRIPT"
      Script file. If "", then last processed script used.


*** Methods list (methods that not attached to the AkelPad window, marked as +ActiveX) ***

AkelPad.GetMainWnd
AkelPad.GetAkelDir
AkelPad.GetInstanceExe
AkelPad.GetInstanceDll                       +ActiveX
AkelPad.GetLangId                            +ActiveX
AkelPad.IsOldWindows                         +ActiveX
AkelPad.IsOldRichEdit
AkelPad.IsOldComctl32
AkelPad.IsAkelEdit
AkelPad.IsMDI
AkelPad.GetEditWnd
AkelPad.SetEditWnd
AkelPad.GetEditDoc
AkelPad.GetEditFile
AkelPad.GetEditCodePage
AkelPad.GetEditBOM
AkelPad.GetEditNewLine
AkelPad.GetEditModified
AkelPad.GetEditReadOnly
AkelPad.SetFrameInfo
AkelPad.SendMessage                          +ActiveX
AkelPad.MessageBox                           +ActiveX
AkelPad.InputBox                             +ActiveX
AkelPad.GetSelStart
AkelPad.GetSelEnd
AkelPad.SetSel
AkelPad.GetSelText
AkelPad.GetTextRange
AkelPad.ReplaceSel
AkelPad.TextFind
AkelPad.TextReplace
AkelPad.GetClipboardText                     +ActiveX
AkelPad.SetClipboardText                     +ActiveX
AkelPad.IsPluginRunning
AkelPad.Call
AkelPad.CallA
AkelPad.CallW
AkelPad.CallEx
AkelPad.CallExA
AkelPad.CallExW
AkelPad.Exec                                 +ActiveX
AkelPad.Command
AkelPad.Font
AkelPad.Recode
AkelPad.Include
AkelPad.IsInclude
AkelPad.OpenFile
AkelPad.ReadFile
AkelPad.SaveFile
AkelPad.SystemFunction                       +ActiveX
AkelPad.SystemFunction().AddParameter        +ActiveX
AkelPad.SystemFunction().Call                +ActiveX
AkelPad.SystemFunction().GetLastError        +ActiveX
AkelPad.SystemFunction().RegisterCallback    +ActiveX
AkelPad.SystemFunction().UnregisterCallback  +ActiveX
AkelPad.MemAlloc                             +ActiveX
AkelPad.MemCopy                              +ActiveX
AkelPad.MemRead                              +ActiveX
AkelPad.MemStrPtr                            +ActiveX
AkelPad.MemFree                              +ActiveX
AkelPad.Debug                                +ActiveX
AkelPad.VarType                              +ActiveX
AkelPad.GetArgLine
AkelPad.GetArgValue
AkelPad.ScriptSettings
AkelPad.ScriptSettings().Begin
AkelPad.ScriptSettings().Read
AkelPad.ScriptSettings().Write
AkelPad.ScriptSettings().Delete
AkelPad.ScriptSettings().End
AkelPad.WindowRegisterClass                  +ActiveX
AkelPad.WindowUnregisterClass                +ActiveX
AkelPad.WindowGetMessage                     +ActiveX
AkelPad.WindowSubClass                       +ActiveX
AkelPad.WindowNextProc                       +ActiveX
AkelPad.WindowNoNextProc                     +ActiveX
AkelPad.WindowUnsubClass                     +ActiveX
AkelPad.ThreadHook                           +ActiveX
AkelPad.ThreadUnhook                         +ActiveX
AkelPad.ScriptNoMutex
AkelPad.ScriptHandle                         +ActiveX
_TCHAR                                       +ActiveX used as AkelPad.Constants._TCHAR
_TSTR                                        +ActiveX used as AkelPad.Constants._TSTR
_TSIZE                                       +ActiveX used as AkelPad.Constants._TSIZE
_X64                                         +ActiveX used as AkelPad.Constants._X64


*** Methods description ***

AkelPad.GetMainWnd
__________________

Get main window handle.

  GetMainWnd();

Return Value
  Number. Main window handle.

Example:
  var hMainWnd=AkelPad.GetMainWnd();


AkelPad.GetAkelDir
__________________

Get AkelPad directory or its subdirectory.

  GetAkelDir([nSubDir]);

Arguments
  nSubDir
    0  //ADTYPE_ROOT       root AkelPad's folder (by default).
    1  //ADTYPE_AKELFILES  "[AkelPad]\AkelFiles".
    2  //ADTYPE_DOCS       "[AkelPad]\AkelFiles\Docs".
    3  //ADTYPE_LANGS      "[AkelPad]\AkelFiles\Langs".
    4  //ADTYPE_PLUGS      "[AkelPad]\AkelFiles\Plugs".
    5  //ADTYPE_SCRIPTS    "[AkelPad]\AkelFiles\Plugs\Scripts".
    6  //ADTYPE_INCLUDE    "[AkelPad]\AkelFiles\Plugs\Scripts\Include".

Return Value
  String. AkelPad directory or its subdirectory.

Example:
  var pAkelDir=AkelPad.GetAkelDir();


AkelPad.GetInstanceExe
______________________

Get EXE instance handle.

  GetInstanceExe();

Return Value
  Number. EXE instance handle.

Example:
  var hInstance=AkelPad.GetInstanceExe();


AkelPad.GetInstanceDll
______________________

Get DLL instance handle.

  GetInstanceDll();

Return Value
  Number. DLL instance handle.

Example:
  var hInstance=AkelPad.GetInstanceDll();


AkelPad.GetLangId
_________________

Get AkelPad language ID.

  GetLangId([nType]);

Arguments
  nType
    0  //LANGID_FULL     full language identifier. This value is a combination of a primary language identifier and a sublanguage identifier (by default).
    1  //LANGID_PRIMARY  primary language identifier.
    2  //LANGID_SUB      sublanguage identifier.

Return Value
  Number. AkelPad language ID.

Example:
  var nLangID=AkelPad.GetLangId(1 /*LANGID_PRIMARY*/);

  if (nLangID == 0x19) //LANG_RUSSIAN
    WScript.Echo("Russian");
  else
    WScript.Echo("Other");


AkelPad.IsOldWindows
____________________

Is non-Unicode Windows.

  IsOldWindows();

Return Value
  true   non-Unicode (Windows 95/98/Me).
  false  Unicode (Windows NT/2000/XP).

Example:
  var bOldWindows=AkelPad.IsOldWindows();


AkelPad.IsOldRichEdit
_____________________

Is riched20.dll lower then 5.30 (v3.0).

  IsOldRichEdit();

Return Value
  true   riched20.dll lower then 5.30 (v2.0).
  false  riched20.dll not lower then 5.30 (v3.0, v4.0).

Example:
  var bOldRichEdit=AkelPad.IsOldRichEdit();


AkelPad.IsOldComctl32
_____________________

Is comctl32.dll lower then 4.71.

  IsOldComctl32();

Return Value
  true   comctl32.dll lower then 4.71.
  false  comctl32.dll not lower then 4.71.

Example:
  var bOldComctl32=AkelPad.IsOldComctl32();


AkelPad.IsAkelEdit
__________________

Check AkelEdit control usage in program or in specified window.

  IsAkelEdit([hWnd]);

Argumets
  hWnd
    Edit window handle. If zero or not specified, then returned AkelEdit usage in program.

Return Value
  0  //ISAEW_NONE     RichEdit control used (AkelPad v3.x.x).
  1  //ISAEW_PROGRAM  AkelEdit control used (AkelPad v4.x.x or higher)
                      or, if handle specified, then this handle is the program AkelEdit window.
  2  //ISAEW_PLUGIN   if handle specified, then this handle is the plugin AkelEdit window (AkelPad v4.x.x or higher).

Example:
  var nAkelEdit=AkelPad.IsAkelEdit();


AkelPad.IsMDI
_____________

Is AkelPad in MDI mode.

  IsMDI();

Return Value
  0  //WMD_SDI   Single document interface (SDI).
  1  //WMD_MDI   Multiple document interface (MDI).
  2  //WMD_PMDI  Pseudo-Multiple document interface (PMDI).

Example:
  var nMDI=AkelPad.IsMDI();


AkelPad.GetEditWnd
__________________

Get active edit window handle.

  GetEditWnd();

Return Value
  Number. Active edit window handle.

Example:
  var hWndEdit=AkelPad.GetEditWnd();


AkelPad.SetEditWnd
__________________

Set active edit window handle manually. After setting methods GetEditWnd,
GetSelStart, GetSelEnd, SetSel, GetSelText, GetTextRange, ReplaceSel will use this handle.

  SetEditWnd(hHandle);

Argumets
  hHandle
    Edit window handle. If zero or hHandle is not AkelEdit/RichEdit20 window or
    hHandle is standard edit window, then handles management is taken by program and
    zero is returned.

Return Value
  Number. Active edit window handle.

Example:
  var hWndOutput;

  if (hWndOutput=GetOutputWindow())
  {
    hWndOutput=AkelPad.SetEditWnd(hWndOutput);
    AkelPad.SetSel(0, -1);
  }

  function GetOutputWindow()
  {
    var lpWnd;
    var hWnd=0;

    if (lpWnd=AkelPad.MemAlloc(_X64?8:4 /*sizeof(HWND)*/))
    {
      AkelPad.Call("Log::Output", 2, lpWnd);
      hWnd=AkelPad.MemRead(lpWnd, 2 /*DT_QWORD*/);
      AkelPad.MemFree(lpWnd);
    }
    return hWnd;
  }


AkelPad.GetEditDoc
__________________

Get active document handle.

  GetEditDoc();

Return Value
  Number. Active document handle.

Example:
  var hDocEdit=AkelPad.GetEditDoc();


AkelPad.GetEditFile
___________________

Get file name.

  GetEditFile(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  String. File name.

Example:
  var pEditFile=AkelPad.GetEditFile(0);


AkelPad.GetEditCodePage
_______________________

Get file code page.

  GetEditCodePage(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  Number. Code page.

Example:
  var nCodePage=AkelPad.GetEditCodePage(0);


AkelPad.GetEditBOM
__________________

Get file BOM.

  GetEditBOM(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  true   file has BOM.
  false  file hasn't BOM.

Example:
  var bBOM=AkelPad.GetEditBOM(0);


AkelPad.GetEditNewLine
______________________

Get file new line format.

  GetEditNewLine(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  1  DOS/Windows (0Dh, 0Ah)
  2  Unix (0Ah)
  3  Mac (0Dh)

Example:
  var nNewLine=AkelPad.GetEditNewLine(0);


AkelPad.GetEditModified
_______________________

Get file modified flag.

  GetEditModified(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  true   contents of edit control have been modified.
  false  contents of edit control haven't been modified.

Example:
  var bModified=AkelPad.GetEditModified(0);


AkelPad.GetEditReadOnly
_______________________

Get edit control's read only mode.

  GetEditReadOnly(hHandle);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.

Return Value
  true   read only mode.
  false  edit mode.

Example:
  var bReadOnly=AkelPad.GetEditReadOnly(0);


AkelPad.SetFrameInfo
____________________

Set frame information.

  SetFrameInfo(lpFrame, nType, dwData);

Arguments
  lpFrame
    Frame data handle. If zero then data handle of the active frame is used.
  nType
    Setting type for change. See description of FIS_* flags in AkelDLL.h.
  dwData
    Setting data.

Return Value
  true   information is changed.
  false  information isn't changed.

Remarks
  Method works on all window modes SDI/MDI/PMDI.

Example:
  AkelPad.SetFrameInfo(0, 1 /*FIS_TABSTOPSIZE*/, 4);


AkelPad.SendMessage
___________________

Send message.

  SendMessage(hHandle, nMessage, wParam, lParam);

Arguments
  hHandle
    Handle to the window whose window procedure will receive the message.
  nMessage
    Specifies the message to be sent.
  wParam
    Specifies additional message-specific information.
  lParam
    Specifies additional message-specific information.

Return Value
  Number. Result of the message processing; it depends on the message sent.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  AkelPad.SendMessage(hMainWnd, 273 /*WM_COMMAND*/, 4101 /*IDM_FILE_NEW*/, 0);


AkelPad.MessageBox
__________________

Show message.

  MessageBox(hHandle, pText, pCaption, nType[, hIcon][, ...]);

Arguments
  hHandle
    Handle to the owner window of the message box to be created. If this parameter is zero, the message box has no owner window.
  pText
    Message to be displayed.
  pCaption
    Dialog box title.
  nType
    Specifies the contents and behavior of the dialog box. See MSDN.
  hIcon
    Icon handle. If zero, icon specified in nType is used.
  ...
    Enumeration of dialog buttons. Each button consists of three elements - nButtonID, pButtonStr, nFlags.
      nButtonID
        Button identifier.
      pButtonStr
        Button text.
      nFlags
        0x1  //BMB_DEFAULT   Default button.
        0x2  //BMB_DISABLED  Button is disabled.

Remarks
  If only first 4 arguments are used, then system message box is called.
  If all arguments are used, then AkelPad extended message box is called.
  If all arguments are used, then nType argument specified only icon type MB_ICON*.

Return Value
  Number. Return value is the button's ID pressed.

Example (standard dialog):
  var hMainWnd=AkelPad.GetMainWnd();
  AkelPad.MessageBox(hMainWnd, "MyText", "MyCaption", 64 /*MB_ICONINFORMATION*/);

Example (extended dialog):
  var hMainWnd=AkelPad.GetMainWnd();
  var nChoice=AkelPad.MessageBox(hMainWnd, "MyText", "MyCaption", 32 /*MB_ICONQUESTION*/, 0,
              1 /*IDOK*/,     "&OK",     0x1 /*BMB_DEFAULT*/,
              2 /*IDCANCEL*/, "&Cancel", 0);
  WScript.Echo("Button ID=" + nChoice);


AkelPad.InputBox
________________

Input dialog box.

  InputBox(hHandle, pCaption, pLabel, pEdit);

Arguments
  hHandle
    Handle to the owner window of the message box to be created.
  pCaption
    Dialog box title.
  pLabel
    Edit box label. It is possible to use \n symbol to create multiline label.
  pEdit
    Edit box text.

Return Value
  String. Edit box text. Cancel button returns undefined.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var pText=AkelPad.InputBox(hMainWnd, "MyCaption", "MyLabel", "MyText");


AkelPad.GetSelStart
___________________

Get selection first char index.

  GetSelStart();

Return Value
  Number. Selection first char index.

Example:
  var nSelStart=AkelPad.GetSelStart();


AkelPad.GetSelEnd
_________________

Get selection last char index.

  GetSelEnd();

Return Value
  Number. Selection last char index.

Example:
  var nSelEnd=AkelPad.GetSelEnd();


AkelPad.SetSel
______________

Set selection.

  SetSel(nSelStart, nSelEnd[, nFlags]);

Arguments
  nSelStart
    Selection first char index.
  nSelEnd
    Selection last char index.
  nFlags
    0x001  //AESELT_COLUMNON              Make column selection ON.
    0x002  //AESELT_COLUMNASIS            Leave column selection as is.
    0x004  //AESELT_LOCKNOTIFY            Disable AEN_SELCHANGING and AEN_SELCHANGED notifications.
    0x008  //AESELT_LOCKSCROLL            Lock edit window scroll.
    0x010  //AESELT_LOCKUPDATE            Lock edit window update.
    0x020  //AESELT_LOCKCARET             Lock caret reposition.
    0x080  //AESELT_NOCARETHORZINDENT     Caret horizontal indent isn't changed.
    0x100  //AESELT_NOVERTSCROLLCORRECT   On some conditions scroll can be increased to a height of one line.

Return Value
  Zero.

Example:
  AkelPad.SetSel(0, 10);


AkelPad.GetSelText
__________________

Get selected text.

  GetSelText([nNewLine]);

Arguments
  nNewLine (only for AkelPad 4.x.x)
    0    //New line without changing.
    1    //"\r" new line (default).
    2    //"\n" new line.
    3    //"\r\n" new line.

Return Value
  String. Selected text.

Example:
  var pSelText=AkelPad.GetSelText();


AkelPad.GetTextRange
____________________

Get text range.

  GetTextRange(nRangeStart, nRangeEnd[, nNewLine]);

Arguments
  nRangeStart
    Range first char index.
  nRangeEnd
    Range last char index.
  nNewLine (only for AkelPad 4.x.x)
    0    //New line without changing.
    1    //"\r" new line (default).
    2    //"\n" new line.
    3    //"\r\n" new line.

Return Value
  String. Text range.

Example:
  var pTextRange=AkelPad.GetTextRange(0, 10);


AkelPad.ReplaceSel
__________________

Replace selection.

  ReplaceSel(pText[, bSelect]);

Arguments
  pText
    Text to replace with.
  bSelect
    true   select inserted text.
    false  don't select inserted text (default).

Return Value
  Zero.

Example:
  AkelPad.ReplaceSel("MyText");


AkelPad.TextFind
________________

Find text.

  TextFind(hHandle, pFindIt, nFlags);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.
  pFindIt
    Text to find.
  nFlags
    0x00000001  //FRF_DOWN               Find down.
    0x00000002  //FRF_WHOLEWORD          Find whole word.
    0x00000004  //FRF_MATCHCASE          Search is case-sensitive.
    0x00080000  //FRF_REGEXP             Search with regular expressions.
    0x00100000  //FRF_UP                 Find up.
    0x00200000  //FRF_BEGINNING          Search from beginning (usage: FRF_DOWN|FRF_BEGINNING).
    0x00400000  //FRF_SELECTION          Search in selection (usage: FRF_DOWN|FRF_SELECTION).
    0x00800000  //FRF_ESCAPESEQ          Search with escape sequences.
    0x01000000  //FRF_ALLFILES           Search in all opened MDI documents (not implemented).
    0x08000000  //FRF_CYCLESEARCH        Cycle search.
    0x10000000  //FRF_CYCLESEARCHPROMPT  Prompt during cycle search.

Return Value
  Number. Character position of the next match.
  If there are no more matches, the return value is 1.
  If there is syntax error in regular expression (with FRF_REGEXP flag), the return value is (100 - PatternOffset).
  For example, pFindIt equal to "ab[c", syntax error in third symbol, return value is 102.

Example:
  var hWndEdit=AkelPad.GetEditWnd();
  AkelPad.TextFind(hWndEdit, "MySearchString", 0x00200001 /*FRF_DOWN|FRF_BEGINNING*/);


AkelPad.TextReplace
___________________

Find and replace text.

  TextReplace(hHandle, pFindIt, pReplaceWith, nFlags, bAll);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.
  pFindIt
    Text to find.
  pReplaceWith
    Text to replace with.
  nFlags
    0x00000001  //FRF_DOWN               Find down.
    0x00000002  //FRF_WHOLEWORD          Find whole word.
    0x00000004  //FRF_MATCHCASE          Search is case-sensitive.
    0x00080000  //FRF_REGEXP             Search with regular expressions.
    0x00100000  //FRF_UP                 Find up.
    0x00200000  //FRF_BEGINNING          Search from beginning (usage: FRF_DOWN|FRF_BEGINNING).
    0x00400000  //FRF_SELECTION          Search in selection (usage: FRF_DOWN|FRF_SELECTION).
    0x00800000  //FRF_ESCAPESEQ          Search with escape sequences.
    0x01000000  //FRF_ALLFILES           Search in all opened MDI documents (not implemented).
    0x08000000  //FRF_CYCLESEARCH        Cycle search (works, if bAll == false).
    0x10000000  //FRF_CYCLESEARCHPROMPT  Prompt during cycle search.
  bAll
    true   replace all.
    false  replace single.

Return Value
  Number. Character position of the next match.
  If there are no more matches, the return value is 1.
  If there is syntax error in regular expression (with FRF_REGEXP flag), the return value is (100 - PatternOffset).
  For example, pFindIt equal to "ab[c", syntax error in third symbol, return value is 102.

Example:
  var hWndEdit=AkelPad.GetEditWnd();
  AkelPad.TextReplace(hWndEdit, "MySearchString", "MyReplaceText", 0x00200001 /*FRF_DOWN|FRF_BEGINNING*/, true);


AkelPad.GetClipboardText
________________________

Get clipboard text.

  GetClipboardText([bAnsi]);

Arguments
  bAnsi
    true   retrieve ansi text.
    false  retrieve unicode text (default).

Return Value
  String. Clipboard text.

Example:
  var pClipboardText=AkelPad.GetClipboardText();


AkelPad.SetClipboardText
________________________

Set clipboard text.

  SetClipboardText(pText);

Arguments
  pText
    Text to set.

Return Value
  Zero.

Example:
  AkelPad.SetClipboardText("MyText");


AkelPad.IsPluginRunning
_______________________

Is AkelPad plugin running.

  IsPluginRunning(pFunction);

Arguments
  pFunction
    Function to check.

Return Value
  true   plugin is running.
  false  plugin isn't running.

Example:
  var bRunning=AkelPad.IsPluginRunning("HighLight::Main");


AkelPad.Call
____________

Call AkelPad plugin.

  Call(pFunction[, ...]);

Arguments
  pFunction
    Function to call.
  ...
    Function parameters.

Remarks
  During plugin call string type determines automatically.

Return Value
   -1  //UD_FAILED               Operation failed.
    0  //UD_UNLOAD               Plugin unloaded.
  0x1  //UD_NONUNLOAD_ACTIVE     Plugin in memory and active.
  0x2  //UD_NONUNLOAD_NONACTIVE  Plugin in memory, but non-active.
  0x4  //UD_NONUNLOAD_UNCHANGE   Plugin in memory.
  0x8  //UD_HOTKEY_DODEFAULT     Hotkey default processing will done.

Example:
  var nResult=AkelPad.Call("Coder::HighLight", 2, "#000000", "#9BFF9B");


AkelPad.CallA
_____________

Same as AkelPad.Call, but force to use Ansi stings during plugin call.


AkelPad.CallW
_____________

Same as AkelPad.Call, but force to use Unicode stings during plugin call.


AkelPad.CallEx
______________

Call AkelPad plugin with flags.

  CallEx(nFlags, pFunction[, ...]);

Arguments
  nFlags
    0x04  //DLLCF_SWITCHAUTOLOAD  If function running after call then turn on autoload, if not then turn off autoload.
    0x08  //DLLCF_SAVENOW         Using with DLLCF_SWITCHAUTOLOAD. Call AKD_DLLSAVE with DLLSF_NOW after switching autoload flag.
    0x10  //DLLCF_SAVEONEXIT      Using with DLLCF_SWITCHAUTOLOAD. Call AKD_DLLSAVE with DLLSF_ONEXIT after switching autoload flag.
  pFunction
    Function to call.
  ...
    Function parameters.

Remarks
  During plugin call string type determines automatically.

Return Value
   -1  //UD_FAILED               Operation failed.
    0  //UD_UNLOAD               Plugin unloaded.
  0x1  //UD_NONUNLOAD_ACTIVE     Plugin in memory and active.
  0x2  //UD_NONUNLOAD_NONACTIVE  Plugin in memory, but non-active.
  0x4  //UD_NONUNLOAD_UNCHANGE   Plugin in memory.
  0x8  //UD_HOTKEY_DODEFAULT     Hotkey default processing will done.

Example:
  var nResult=AkelPad.CallEx(0x14 /*DLLCF_SWITCHAUTOLOAD|DLLCF_SAVEONEXIT*/, "Coder::HighLight");


AkelPad.CallExA
_______________

Same as AkelPad.CallEx, but force to use Ansi stings during plugin call.


AkelPad.CallExW
_______________

Same as AkelPad.CallEx, but force to use Unicode stings during plugin call.


AkelPad.Exec
____________

Execute program.

  Exec(pCommandLine[, pWorkDirectory][, nWait]);

Arguments
  pCommandLine
    Command line.
  pWorkDirectory
    Working directory. Default is "".
  nWait
    0  returns immediately after starting the program, automatically returning 0 (default).
    1  waits until the program finishes and returns any error code returned by the program.
    2  waits until the specified process is waiting for user input, automatically returning 0.

Return Value
  Number. Exit code.

Example:
  AkelPad.Exec("notepad.exe");


AkelPad.Command
_______________

Call AkelPad internal command.

  Command(nCmd);

Arguments
  nCmd
    Internal command number.

Return Value
  Number. Depend on command.

Example:
  AkelPad.Command(4101 /*IDM_FILE_NEW*/);


AkelPad.Font
____________

Set font.

  Font(pFont, nStyle, nSize);

Arguments
  pFont
    Font face, for example, "Courier". Unchanged, if "".
  nStyle
    0 ignored.
    1 normal.
    2 bold.
    3 italic.
    4 bold italic.
  nSize
    Font size. Unchanged, if 0.

Return Value
  Zero.

Example:
  AkelPad.Font("Courier", 4, 10)


AkelPad.Recode
______________

Recode selection.

  Recode(nCodePageFrom, nCodePageTo);

Arguments
  nCodePageFrom
    Recode codepage source. If -1, it will be autodetected.
  nCodePageTo
    Recode codepage target. If -1, it will be autodetected.

Return Value
  Zero.

Example:
  AkelPad.Recode(1252, 437);


AkelPad.Include
_______________

Add code from file.

  Include(pFileName);

Arguments
  pFileName
    File name, that located in "[AkelPad]\AkelFiles\Plugs\Scripts\Include" directory.

Remarks
  Method Include is the same as code eval(AkelPad.ReadFile("...")), but allow to detect error placement in include file, if error appear.

Return Value
  true   success.
  false  failed.

Example:
  var pParent;

  AkelPad.Include("CommonFunctions.js");
  pParent=GetParent("C:\\Program Files\\1.txt");
  WScript.Echo(pParent);


AkelPad.IsInclude
_________________

Detect is script executed with AkelPad.Include() method.

  IsInclude();

Return Value
  String. Include file name, if script executed with AkelPad.Include() method or "" otherwise.

Example:
  WScript.Echo("" + AkelPad.IsInclude());


AkelPad.OpenFile
________________

Open file.

  OpenFile(pFile[, nFlags][, nCodePage][, bBOM]);

Arguments
  pFile
    File to open.
  nFlags
    0x001  //OD_ADT_BINARY_ERROR     Check if file is binary.
    0x002  //OD_ADT_REG_CODEPAGE     If last open code page found in registry, then it will be
           //                        used with OD_ADT_DETECT_BOM flag, if not found, then next flags
           //                        will be used OD_ADT_DETECT_CODEPAGE|OD_ADT_DETECT_BOM.
    0x004  //OD_ADT_DETECT_CODEPAGE  Detect code page.
    0x008  //OD_ADT_DETECT_BOM       Detect BOM mark.
    0x010  //OD_ADT_NOMESSAGES       No messages, if errors in autodetect.
    0x100  //OD_REOPEN               Don't create new MDI window, use the exited one.
    0x200  //OD_NOSCROLL             Don't restore scroll position.                  
         //Default is 0xD          (OD_ADT_BINARY_ERROR|OD_ADT_DETECT_CODEPAGE|OD_ADT_DETECT_BOM).
  nCodePage
    File code page, ignored if (nFlags & OD_ADT_DETECT_CODEPAGE)
  bBOM
    File BOM, ignored if (nFlags & OD_ADT_DETECT_BOM)

Return Value
   0  //EOD_SUCCESS          Success.
  -1  //EOD_ADT_OPEN         Autodetect codepage, can't open file.
  -2  //EOD_ADT_ALLOC        Autodetect codepage, can't allocate buffer.
  -3  //EOD_ADT_READ         Autodetect codepage, read file error.
 -11  //EOD_OPEN             Can't open file.
 -13  //EOD_WINDOW_EXIST     File already opened.
 -14  //EOD_CODEPAGE_ERROR   Code page isn't implemented.
 -15  //EOD_STOP             Stopped from AKDN_OPENDOCUMENT_START.
 -16  //EOD_STREAMIN         Error in EM_STREAMIN.
 -17  //EOD_DOCUMENTS_LIMIT  Documents limit reached in MDI mode.
 -20  //EOD_MSGNO            File is skipped.
 -21  //EOD_MSGCANCEL        User press cancel.

Example:
  var bResult=AkelPad.OpenFile("C:\\MyFile.txt");


AkelPad.ReadFile
________________

Read contents of a file.

  ReadFile(pFile[, nFlags][, nCodePage][, bBOM][, nBytesMax]);

Arguments
  pFile
    File to read.
  nFlags
    0x1  //OD_ADT_BINARY_ERROR     Check if file is binary.
    0x2  //OD_ADT_REG_CODEPAGE     If last open code page found in registry, then it will be
         //                        used with OD_ADT_DETECT_BOM flag, if not found, then next flags
         //                        will be used OD_ADT_DETECT_CODEPAGE|OD_ADT_DETECT_BOM.
    0x4  //OD_ADT_DETECT_CODEPAGE  Detect code page.
    0x8  //OD_ADT_DETECT_BOM       Detect BOM mark.
         //Default is 0xD          (OD_ADT_BINARY_ERROR|OD_ADT_DETECT_CODEPAGE|OD_ADT_DETECT_BOM).
  nCodePage
    File code page, ignored if (nFlags & OD_ADT_DETECT_CODEPAGE).
  bBOM
    File BOM, ignored if (nFlags & OD_ADT_DETECT_BOM).
  nBytesMax
    Read specified number of first bytes in file. If -1, entire file will be read (default).

Return Value
  String. Contents of a file.

Example:
  var pText=AkelPad.ReadFile("C:\\MyFile.txt");


AkelPad.SaveFile
________________

Save document.

  SaveFile(hHandle, pFile[, nCodePage][, bBOM][, nFlags]);

Arguments
  hHandle
    Edit window handle. If zero then active edit window handle is used.
  pFile
    File name to save to.
  nCodePage
    Save codepage. If -1 or not specified, current codepage will be used.
  bBOM
    File byte order mark. 1 - exist, 0 - doesn't exist, -1 or not specified - current BOM will be used.
  nFlags
    0x1  //SD_UPDATE       Update file info in program.
    0x2  //SD_SELECTION    Save only selection.
         //Default is 0x1  (SD_UPDATE).

Return Value
   0  //ESD_SUCCESS         Success.
  -1  //ESD_OPEN            Can't open file.
  -2  //ESD_WRITE           Can't write to file.
  -3  //ESD_READONLY        File has read-only attribute.
  -4  //ESD_CODEPAGE_ERROR  Code page isn't implemented.
  -5  //ESD_STOP            Stopped from AKDN_SAVEDOCUMENT_START.
  -6  //ESD_STREAMOUT       Error in EM_STREAMOUT.

Example:
  var hWndEdit=AkelPad.GetEditWnd();
  var nResult=AkelPad.SaveFile(hWndEdit, "C:\\MyFile.txt");


AkelPad.SystemFunction
______________________

Create system function object.

  SystemFunction();

Return Value
  Object. System function object.

Example:
  var oSys=AkelPad.SystemFunction();


AkelPad.SystemFunction().AddParameter
_____________________________________

Add function parameter.

  AddParameter(vParameter);

Arguments
  vParameter
    Function parameter.

Return Value
  Zero.

Example:
  See AkelPad.SystemFunction().Call old syntax example.


AkelPad.SystemFunction().Call
_____________________________

Call system function.

  Call(pDllFunction[, ...]);

Arguments
  pDllFunction
    Function name in format "Dll::Function".
  ...
    Function parameters, must be integer, pointer or string.
    String parameter: in Windows 95/98/Me - Ansi string,
                      in Windows NT/2000/XP - Unicode string.

Return Value
  Number. Call result.

Example (new syntax):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  oSys.Call("user32::ShowWindow", hMainWnd, 6 /*SW_MINIMIZE*/);

Example (old syntax):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  oSys.AddParameter(hMainWnd);
  oSys.AddParameter(6 /*SW_MINIMIZE*/);
  oSys.Call("user32::ShowWindow");


AkelPad.SystemFunction().GetLastError
_____________________________________

Get call function last error.

  GetLastError();

Return Value
  Number. Call function last error.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var nError;
  oSys.Call("user32::ShowWindow", hMainWnd, 6 /*SW_MINIMIZE*/);
  nError=oSys.GetLastError();


AkelPad.SystemFunction().RegisterCallback
_________________________________________

Register callback function.

  RegisterCallback(pFunction[, lpCallback][, nArgCount]);

Arguments
  pFunction
    String of function name.
  lpCallback
    Callback function. See Remarks section.
  nArgCount
    Argument count in callback function. See Remarks section.

Remarks
  If lpCallback and nArgCount arguments specified, pFunction is ignored.
  Using lpCallback and nArgCount arguments is the only way to make RegisterCallback work in VBScript and ActiveX.
  The maximum number of working callback functions at the same time is 4.

Return Value
  Object. Pointer on function.

Example (callback under JScript):
  var oSys=AkelPad.SystemFunction();
  var lpEnumWindowsCallback;
  var nStopAfter=3;

  if (lpEnumWindowsCallback=oSys.RegisterCallback("EnumWindowsProc"))
  {
    oSys.Call("user32::EnumWindows", lpEnumWindowsCallback, 0);
    oSys.UnregisterCallback(lpEnumWindowsCallback);
  }

  function EnumWindowsProc(hWnd, lParam)
  {
    //Convert hWnd to hex
    if (hWnd < 0) hWnd=(0xFFFFFFFF + 1) + hWnd;
    hWnd="0x" + hWnd.toString(16).toUpperCase();

    //Show parameters
    WScript.Echo("hWnd=" + hWnd + "; lParam=" + lParam);

    if (--nStopAfter <= 0)
      return false;
    else
      return true;
  }

Example (callback under VBScript):
  set oSys=AkelPad.SystemFunction()
  nStopAfter=3
  
  set lpEnumWindowsCallback = oSys.RegisterCallback ("", GetRef("EnumWindowsProc"), 2)
  oSys.Call "user32::EnumWindows", lpEnumWindowsCallback, 0
  oSys.UnregisterCallback lpEnumWindowsCallback
  
  Function EnumWindowsProc(hWnd, lParam)
    'Convert hWnd to hex
    hWnd="0x" & Hex(hWnd)
  
    'Show parameters
    WScript.Echo "hWnd=" & hWnd & "; lParam=" & lParam
  
    nStopAfter = nStopAfter - 1
    if nStopAfter <= 0 Then
      EnumWindowsProc = 0
    else
      EnumWindowsProc = 1
    end if
  End Function

Example (callback under ActiveX):
  var AkelPad=new ActiveXObject("AkelPad.Document");
  var oSys=AkelPad.SystemFunction();
  var lpEnumWindowsCallback;
  var nStopAfter=3;

  if (lpEnumWindowsCallback=oSys.RegisterCallback("", EnumWindowsProc, 2))
  {
    oSys.Call("user32::EnumWindows", lpEnumWindowsCallback, 0);
    oSys.UnregisterCallback(lpEnumWindowsCallback);
  }

  function EnumWindowsProc(hWnd, lParam)
  {
    //Convert hWnd to hex
    if (hWnd < 0) hWnd=(0xFFFFFFFF + 1) + hWnd;
    hWnd="0x" + hWnd.toString(16).toUpperCase();

    //Show parameters
    WScript.Echo("hWnd=" + hWnd + "; lParam=" + lParam);

    if (--nStopAfter <= 0)
      return false;
    else
      return true;
  }


AkelPad.SystemFunction().UnregisterCallback
___________________________________________

Remove callback function registration.

  UnregisterCallback(oFunction);

Arguments
  oFunction
    Pointer on function.

Return Value
  Zero.

Example:
  See RegisterCallback example.


AkelPad.MemAlloc
________________

Allocate memory.

  MemAlloc(nSize);

Arguments
  nSize
    Size in bytes to allocate.

Return Value
  Number. Pointer to a buffer.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var pMessage="MyMessage";
  var pCaption="MyCaption";
  var lpMessageBuffer;
  var lpCaptionBuffer;

  if (lpMessageBuffer=AkelPad.MemAlloc(256))
  {
    AkelPad.MemCopy(lpMessageBuffer, pMessage.substr(0, 255), 0 /*DT_ANSI*/);

    if (lpCaptionBuffer=AkelPad.MemAlloc(256))
    {
      AkelPad.MemCopy(lpCaptionBuffer, pCaption.substr(0, 255), 0 /*DT_ANSI*/);

      oSys.Call("user32::MessageBoxA", hMainWnd, lpMessageBuffer, lpCaptionBuffer, 64 /*MB_ICONINFORMATION*/);

      AkelPad.MemFree(lpCaptionBuffer);
    }
    AkelPad.MemFree(lpMessageBuffer);
  }


AkelPad.MemCopy
_______________

Copy memory.

  MemCopy(lpPointer, vData, nType[, nLength]);

Arguments
  lpPointer
    Pointer to a buffer.
  vData
    Data to copy.
  nType
    Type of the vData parameter:
    0  //DT_ANSI        Copy Ansi string to memory.
    1  //DT_UNICODE     Copy Unicode string to memory.
    2  //DT_QWORD       Copy QWORD number to memory on x64 or DWORD number on x86.
    3  //DT_DWORD       Copy DWORD number to memory.
    4  //DT_WORD        Copy WORD number to memory.
    5  //DT_BYTE        Copy BYTE number to memory.
  nLength
    String length. If -1, all string is copied (default is -1). For DT_ANSI and DT_UNICODE.

Return Value
  Number. Bytes copied.

Example:
  See MemAlloc example.


AkelPad.MemRead
_______________

Read memory.

  MemRead(lpPointer, nType[, nLength]);

Arguments
  lpPointer
    Pointer to a buffer.
  nType
    0  //DT_ANSI        Read Ansi string from memory.
    1  //DT_UNICODE     Read Unicode string from memory.
    2  //DT_QWORD       Read QWORD number from memory on x64 or DWORD number on x86.
    3  //DT_DWORD       Read DWORD number from memory.
    4  //DT_WORD        Read WORD number from memory.
    5  //DT_BYTE        Read BYTE number from memory.
  nLength
    String length. If -1, string is terminated with NULL symbol (default is -1). For DT_ANSI and DT_UNICODE.

Return Value
  String or number.

Example:
  var oSys=AkelPad.SystemFunction();
  var lpDirBuffer;
  var pWinDir;

  if (lpDirBuffer=AkelPad.MemAlloc(256))
  {
    oSys.Call("kernel32::GetWindowsDirectoryA", lpDirBuffer, 256);
    pWinDir=AkelPad.MemRead(lpDirBuffer, 0 /*DT_ANSI*/);

    AkelPad.MemFree(lpDirBuffer);
  }


AkelPad.MemStrPtr
_________________

Get pointer to a script unicode string.

  MemStrPtr(pString);

Arguments
  pString
    Constant string or string object.

Return Value
  Number. Pointer to a unicode string.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  AkelPad.SendMessage(hMainWnd, 1206 /*AKD_GOTOW*/, 0x1 /*GT_LINE*/, AkelPad.MemStrPtr("10:3"));


AkelPad.MemFree
_______________

Free memory.

  MemFree(lpPointer);

Arguments
  lpPointer
    Pointer to a buffer.

Return Value
  Zero.

Example:
  See MemAlloc example.


AkelPad.Debug
_____________

Debug memory usage.

  Debug([dwType]);

Arguments
  dwType
    0x1  //DBG_MEMREAD     Debug memory read.
    0x2  //DBG_MEMWRITE    Debug memory write.
    0x4  //DBG_MEMFREE     Debug memory free.
    0x8  //DBG_MEMLEAK     Debug memory leak.
         //Default is 0xf  (DBG_MEMREAD|DBG_MEMWRITE|DBG_MEMFREE|DBG_MEMLEAK).

Return Value
  Previous dwType value.

Example:
  var lpBuffer;

  AkelPad.Debug();

  if (lpBuffer=AkelPad.MemAlloc(2))
  {
    AkelPad.MemCopy(lpBuffer, 123, 3 /*DT_DWORD*/);

    AkelPad.MemFree(lpBuffer);
  }


AkelPad.VarType
_______________

Retrieve variable type.

  VarType(vData);

Arguments
  vData
    Variable.

Return Value
  Number. Type (VARTYPE) of variable (VARIANT).
       0 //VT_EMPTY
       1 //VT_NULL
       2 //VT_I2
       3 //VT_I4
       4 //VT_R4
       5 //VT_R8
       6 //VT_CY
       7 //VT_DATE
       8 //VT_BSTR
       9 //VT_DISPATCH
      10 //VT_ERROR
      11 //VT_BOOL
      12 //VT_VARIANT
      13 //VT_UNKNOWN
      14 //VT_DECIMAL
      16 //VT_I1
      17 //VT_UI1
      18 //VT_UI2
      19 //VT_UI4
      20 //VT_I8
      21 //VT_UI8
      22 //VT_INT
      23 //VT_UINT
      24 //VT_VOID
      25 //VT_HRESULT
      26 //VT_PTR
      27 //VT_SAFEARRAY
      28 //VT_CARRAY
      29 //VT_USERDEFINED
      30 //VT_LPSTR
      31 //VT_LPWSTR
      36 //VT_RECORD
      37 //VT_INT_PTR
      38 //VT_UINT_PTR
      64 //VT_FILETIME
      65 //VT_BLOB
      66 //VT_STREAM
      67 //VT_STORAGE
      68 //VT_STREAMED_OBJECT
      69 //VT_STORED_OBJECT
      70 //VT_BLOB_OBJECT
      71 //VT_CF
      72 //VT_CLSID
      73 //VT_VERSIONED_STREAM
  0x0fff //VT_BSTR_BLOB
  0x1000 //VT_VECTOR
  0x2000 //VT_ARRAY
  0x4000 //VT_BYREF
  0x8000 //VT_RESERVED
  0xffff //VT_ILLEGAL
  0x0fff //VT_ILLEGALMASKED
  0x0fff //VT_TYPEMASK

Example:
  var pString="123";
  WScript.Echo("" + AkelPad.VarType(pString));


AkelPad.GetArgLine
__________________

Retrieve argument line.

  GetArgLine([bNoEncloseQuotes]);

Arguments
  bNoEncloseQuotes
    true   Exclude enclose quotes (by default).
    false  Leave enclose quotes.

Return Value
  String. Argument line.

Example:
  var pArgLine;

  if (pArgLine=AkelPad.GetArgLine(0))
    WScript.Echo(pArgLine);


AkelPad.GetArgValue
___________________

Retrieve argument value by name.

  GetArgValue(pArgName, vDefault);

Arguments
  pArgName
    Argument name.
  vDefault
    Default value. Set if specified argument name not found.

Return Value
  Argument value. Type inherited from default value.

Example:
  //Script was invoked as follows:
  //Call("Scripts::Main", 1, "MyScript.js", `-ArgName1=0.01 -ArgName2="Value2" /ArgName3=0x10`)

  //Get values 0.01, Value2, 0x10 by names ArgName1, ArgName2, ArgName3.
  var nArg1=AkelPad.GetArgValue("ArgName1", 0);
  var pArg2=AkelPad.GetArgValue("ArgName2", "");
  var nArg3=AkelPad.GetArgValue("ArgName3", 0);

  WScript.Echo("VarType=" + AkelPad.VarType(nArg1) + "; ArgValue=" + nArg1 + "\r" +
               "VarType=" + AkelPad.VarType(pArg2) + "; ArgValue=" + pArg2 + "\r" +
               "VarType=" + AkelPad.VarType(nArg3) + "; ArgValue=" + nArg3 + "\r");


AkelPad.ScriptSettings
______________________

Create script settings object.

  ScriptSettings();

Return Value
  Object. Script settings object.

Example:
  var oSet=AkelPad.ScriptSettings();


AkelPad.ScriptSettings().Begin
______________________________

Begin settings operations.

  Begin(pScriptBaseName, nFlags);

Arguments
  pScriptBaseName
    Script name without extension.
  nFlags
    0x1  //POB_READ   Begins read options.
    0x2  //POB_SAVE   Begins save options.
    0x4  //POB_CLEAR  Begins new save options (POB_SAVE|POB_CLEAR).

Return Value
  Number. Settings handle.

Example:
  See Read, Write and Delete examples.


AkelPad.ScriptSettings().Read
_____________________________

Read option.

  Read(pOptionName, nType[, vDefault]);

Arguments
  pOptionName
    Option name.
  nType
    1   //PO_DWORD   Read 32-bit number (DWORD).
    2   //PO_BINARY  Read binary data in any form.
    3   //PO_STRING  Read string.
  vDefault
    Default data.

Return Value
  String or number.

Example:
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin(WScript.ScriptBaseName, 0x1 /*POB_READ*/))
  {
    pString=oSet.Read("String", 3 /*PO_STRING*/);
    bMultiline=oSet.Read("Multiline", 1 /*PO_DWORD*/);

    oSet.End();
  }


AkelPad.ScriptSettings().Write
______________________________

Write option.

  Write(pOptionName, nType, vData[, nDataSize]);

Arguments
  pOptionName
    Option name.
  nType
    1   //PO_DWORD   Write 32-bit number (DWORD).
    2   //PO_BINARY  Write binary data in any form.
    3   //PO_STRING  Write string.
  vData
    Data to write.
  nDataSize
    Data size in bytes. Can be omitted if PO_DWORD or PO_STRING used (default is -1).

Return Value
  Number. Written data size in bytes.

Example:
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin(WScript.ScriptBaseName, 0x2 /*POB_SAVE*/))
  {
    oSet.Write("String", 3 /*PO_STRING*/, "Str1");
    oSet.Write("Sensitive", 1 /*PO_DWORD*/, true);

    oSet.End();
  }


AkelPad.ScriptSettings().Delete
_______________________________

Delete option.

  Delete(pOptionName);

Arguments
  pOptionName
    Option name.

Return Value
  true   success.
  false  failed.

Example:
  var oSet=AkelPad.ScriptSettings();

  if (oSet.Begin(WScript.ScriptBaseName, 0x2 /*POB_SAVE*/))
  {
    oSet.Delete("String");
    oSet.Delete("Sensitive");

    oSet.End();
  }


AkelPad.ScriptSettings().End
____________________________

End settings operations.

  End();

Return Value
  true   success.
  false  failed.

Example:
  See Read, Write and Delete examples.


AkelPad.WindowRegisterClass
___________________________

Register window class.

  WindowRegisterClass(pClassName);

Arguments
  pClassName
    Class name to register.

Return Value
  Number. Class atom that uniquely identifies the class being registered.

Example (JScript):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var hInstanceDLL=AkelPad.GetInstanceDll();
  var hWndDialog;

  if (hMainWnd)
  {
    if (AkelPad.WindowRegisterClass("NewClass"))
    {
      //Create dialog
      hWndDialog=oSys.Call("user32::CreateWindowEx" + _TCHAR,
                           0,                //dwExStyle
                           "NewClass",       //lpClassName
                           0,                //lpWindowName
                           0x90CA0000,       //WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
                           0,                //x
                           0,                //y
                           351,              //nWidth
                           179,              //nHeight
                           hMainWnd,         //hWndParent
                           0,                //ID
                           hInstanceDLL,     //hInstance
                           DialogCallback);  //Script function callback. To use it class must be registered by WindowRegisterClass.

      if (hWndDialog)
      {
        //Disable main window, to make dialog modal
        oSys.Call("user32::EnableWindow", hMainWnd, false);

        //Message loop
        AkelPad.WindowGetMessage();
      }
      AkelPad.WindowUnregisterClass("NewClass");
    }
  }

  function DialogCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 1 /*WM_CREATE*/)
    {
    }
    else if (uMsg == 256 /*WM_KEYDOWN*/)
    {
      if (wParam == 27 /*VK_ESCAPE*/)
      {
        //Escape key pushes Cancel button
        oSys.Call("user32::PostMessage" + _TCHAR, hWndDialog, 273 /*WM_COMMAND*/, 2 /*IDCANCEL*/, 0);
      }
    }
    else if (uMsg == 273 /*WM_COMMAND*/)
    {
      if ((wParam & 0xffff) == 2 /*IDCANCEL*/)
      {
        oSys.Call("user32::PostMessage" + _TCHAR, hWndDialog, 16 /*WM_CLOSE*/, 0, 0);
      }
    }
    else if (uMsg == 16 /*WM_CLOSE*/)
    {
      //Enable main window
      oSys.Call("user32::EnableWindow", hMainWnd, true);

      //Destroy dialog
      oSys.Call("user32::DestroyWindow", hWnd);
    }
    else if (uMsg == 2 /*WM_DESTROY*/)
    {
      //Exit message loop
      oSys.Call("user32::PostQuitMessage", 0);
    }
    return 0;
  }


Example (VBScript):
  'Variables
  hMainWnd=AkelPad.GetMainWnd()
  hInstanceDLL=AkelPad.GetInstanceDll()
  set oSys=AkelPad.SystemFunction()
  set lpCallbackPtr=GetRef("DialogCallback")
  hWndDialog=0

  'VBScript deny names start with (_) underscore
  if AkelPad.IsOldWindows() then
    TCHAR="A"
    TSIZE=1
    TSTR=0
  else
    TCHAR="W"
    TSIZE=2
    TSTR=1
  end if

  'Constants
  Const WM_CREATE=1
  Const WM_KEYDOWN=256
  Const WM_COMMAND=273
  Const WM_CLOSE=16
  Const WM_DESTROY=2
  Const VK_ESCAPE=27
  Const IDCANCEL=2

  if hMainWnd then
    if AkelPad.WindowRegisterClass("NewClass") then

      'Create dialog WS_VISIBLE|WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
      hWndDialog=oSys.Call("user32::CreateWindowEx" & TCHAR, 0, "NewClass", 0, &H90CA0000, 0, 0, 351, 179, hMainWnd, 0, hInstanceDLL, lpCallbackPtr)

      if hWndDialog then
        'Disable main window, to make dialog modal
        oSys.Call "user32::EnableWindow", hMainWnd, false

        'Message loop
        AkelPad.WindowGetMessage()
      end if

      AkelPad.WindowUnregisterClass "NewClass"
    end if
  end if

  Function DialogCallback(hWnd, uMsg, wParam, lParam)
    if uMsg = WM_CREATE then
    elseif uMsg = WM_KEYDOWN then
      if wParam = VK_ESCAPE then
        'Escape key pushes Cancel button
        oSys.Call "user32::PostMessage" & TCHAR, hWndDialog, WM_COMMAND, IDCANCEL, 0
      end if
    elseif uMsg = WM_COMMAND then
      if (wParam And &Hffff) = IDCANCEL then
        oSys.Call "user32::PostMessage" & TCHAR, hWndDialog, WM_CLOSE, 0, 0
      end if
    elseif uMsg = WM_CLOSE then
      'Enable main window
      oSys.Call "user32::EnableWindow", hMainWnd, true

      'Destroy dialog
      oSys.Call "user32::DestroyWindow", hWnd
    elseif uMsg = WM_DESTROY then
      'Exit message loop
      oSys.Call "user32::PostQuitMessage", 0
    end if
    DialogCallback=0
  End Function


AkelPad.WindowUnregisterClass
_____________________________

Unregister window class.

  WindowUnregisterClass(pClassName);

Arguments
  pClassName
    Class name to unregister.

Return Value
  true   success.
  false  failed.

Example:
  See WindowRegisterClass example.


AkelPad.WindowGetMessage
________________________

Process thread messages (message loop).

  WindowGetMessage();

Return Value
  Zero.

Example:
  See WindowRegisterClass example.


AkelPad.WindowSubClass
______________________

Install capture for window messages.

  WindowSubClass(hHandle, lpFunction[, ...]);

Arguments
  hHandle
    Window handle or one of the following values:
      1   //WSC_MAINPROC   Install capture for main window messages.
      2   //WSC_EDITPROC   Install capture for all edit windows messages.
      3   //WSC_FRAMEPROC  Install capture for all MDI frames messages.
  lpFunction
    Function with 4 arguments, in which messages will come.
  ...
    Message filter. Will come only specified messages. If not specified, all messages will come.

Return Value
  Number. Capture handle.

Example:
  var oSys=AkelPad.SystemFunction();
  var hSubClass;
  var nSelStart;

  if (hSubClass=AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 258 /*WM_CHAR*/))
  {
    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
  }

  function EditCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 258 /*WM_CHAR*/)
    {
      if (String.fromCharCode(wParam) == "q")
      {
        AkelPad.MessageBox(0, "Key \"" + String.fromCharCode(wParam) + "\" is pressed. Exiting script...", "", 0);

        //Exit message loop
        oSys.Call("user32::PostQuitMessage", 0);
      }
      else
      {
        //First do default processing
        AkelPad.WindowNextProc(hSubClass, hWnd, uMsg, wParam, lParam);

        //After default processing we can select inserted character
        nSelStart=AkelPad.GetSelStart();
        AkelPad.SetSel(nSelStart - 1, nSelStart);

        //We already do default processing, so skip it
        AkelPad.WindowNoNextProc(hSubClass);
        return 0;
      }
    }
  }


AkelPad.WindowNextProc
______________________

Send message to the next procedure in chain.

  WindowNextProc(hSubClass, hWnd, nMessage, wParam, lParam);

Arguments
  hSubClass
    Capture handle.
  hWnd
    Handle to the window whose window procedure will receive the message.
  nMessage
    Specifies the message to be sent.
  wParam
    Specifies additional message-specific information.
  lParam
    Specifies additional message-specific information.

Return Value
  Number. Result returned by next procedure.

Example:
  See WindowSubClass example.


AkelPad.WindowNoNextProc
________________________

Prevent sending current message to the next procedure in chain.

  WindowNoNextProc(hSubClass);

Arguments
  hSubClass
    Capture handle.

Return Value
  Zero.

Example:
  See WindowSubClass example.


AkelPad.WindowUnsubClass
________________________

Remove capture for window messages.

  WindowUnsubClass(hHandle);

Arguments
  hHandle
    Window handle or one of the following values:
      1   //WSC_MAINPROC   Remove capture of main window messages.
      2   //WSC_EDITPROC   Remove capture of edit windows messages.
      3   //WSC_FRAMEPROC  Remove capture of MDI frames messages.

Return Value
  Zero.

Example:
  See WindowSubClass example.


AkelPad.ThreadHook
__________________

Install hook for thread.

  ThreadHook(nId, lpFunction, nThreadId);

Arguments
  nId
    See first parameter of SetWindowsHookEx in MSDN.
  lpFunction
    Function with 3 arguments, which will be called.
  nThreadId
    Thread identifier. Global hook installing is not supported.

Return Value
  Number. Hook handle.

Remarks
  The maximum number of installed hooks at the same time is 4.

Example:
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var dwMainThreadID=oSys.Call("user32::GetWindowThreadProcessId", hMainWnd, 0);
  var hHook;

  if (hHook=AkelPad.ThreadHook(3 /*WH_GETMESSAGE*/, HookCallback, dwMainThreadID))
  {
    //Message loop
    AkelPad.WindowGetMessage();

    AkelPad.ThreadUnhook(hHook);
  }

  function HookCallback(nCode, wParam, lParam)
  {
    var uMsg=AkelPad.MemRead(lParam + (_X64?8:4) /*offsetof(MSG, message)*/, 3 /*DT_DWORD*/);

    if (uMsg == 0x100 /*WM_KEYDOWN*/)
    {
      wParam=AkelPad.MemRead(lParam + (_X64?16:8) /*offsetof(MSG, wParam)*/, 2 /*DT_QWORD*/);

      AkelPad.MessageBox(0, "Key \"" + String.fromCharCode(wParam) + "\" with code \"" + wParam + "\" is pressed.", "", 0);

      //Exit message loop
      oSys.Call("user32::PostQuitMessage", 0);
    }
  }


AkelPad.ThreadUnhook
____________________

Remove hook from thread.

  ThreadUnhook(hHandle);

Arguments
  hHandle
    Hook handle.

Return Value
  Zero.

Example:
  See ThreadHook example.


AkelPad.ScriptNoMutex
_____________________

Change synchronization object.

  ScriptNoMutex([nUnlockType]);

Arguments
  nUnlockType
    0x1  //ULT_UNLOCKSCRIPTSQUEUE   Allow other scripts running with this script at the same time (by default).
    0x2  //ULT_UNLOCKPROGRAMTHREAD  Unlock main thread from waiting this script. Only if script is called with extenal call with code 2.
    0x4  //ULT_LOCKMULTICOPY        Deny execution of the multiple script copies. By default execution is not denied.
    0x8  //ULT_UNLOCKMULTICOPY      Allow execution of the multiple script copies.

Return Value
  Number. Changed synchronization objects, see nUnlockType.

Example:
  AkelPad.ScriptNoMutex();


AkelPad.ScriptHandle
____________________

Allows to interact with the other running scripts.

  ScriptHandle(vData, nOperation);

Arguments
  vData
    Input data.
  nOperation
    1   //SH_FIRSTSCRIPT  Retrieve first script handle in stack.
        //  vData: zero.
        //  Return value: first script handle in stack.
    2   //SH_THISSCRIPT  Retrieve current script handle in stack.
        //  vData: zero.
        //  Return value: current script handle in stack.
    3   //SH_FINDSCRIPT  Find script handle by its name.
        //  vData: script name.
        //  Return value: first found working script handle in stack.
    11  //SH_GETTHREADHANDLE  Retrieve script thread handle.
        //  vData: script handle.
        //  Return value: script thread handle.
    12  //SH_GETTHREADID  Retrieve script thread identifier.
        //  vData: script handle.
        //  Return value: script thread identifier.
    13  //SH_GETMESSAGELOOP  Retrieve message loop existence in script thread.
        //  vData: script handle.
        //  Return value: true - exist, false - not exist.
    21  //SH_GETNAME  Retrieve script name.
        //  vData: script handle.
        //  Return value: script name.
    22  //SH_GETFILE  Retrieve script file.
        //  vData: script handle.
        //  Return value: script file.
    23  //SH_GETNCLUDE  Retrieve include script file.
        //  vData: script handle.
        //  Return value: include script file.
    24  //SH_GETARGUMENTS  Retrieve script arguments string.
        //  vData: script handle.
        //  Return value: script arguments string.
    31  //SH_NEXTSCRIPT   Retrieve next script handle in stack regardless of the name.
        //  vData: script handle.
        //  Return value: next script handle in stack.
    32  //SH_NEXTSAMESCRIPT  Retrieve next script handle in stack with the same name.
        //  vData: script handle.
        //  Return value: next script handle in stack with the same name.
    33  //SH_CLOSESCRIPT  Exit from script thread's message loop.
        //  vData: script handle.
        //  Return value: zero.

Return Value
  Depend on operation.

Example (deny changing font size by scrolling mouse wheel with Ctrl key):
  var hMainWnd=AkelPad.GetMainWnd();
  var oSys=AkelPad.SystemFunction();
  var hSubClass;
  var hScript;

  if ((hScript=AkelPad.ScriptHandle(WScript.ScriptName, 3 /*SH_FINDSCRIPT*/)) && AkelPad.ScriptHandle(hScript, 13 /*SH_GETMESSAGELOOP*/))
  {
    //Script is running, second call close it.
    AkelPad.ScriptHandle(hScript, 33 /*SH_CLOSESCRIPT*/);
  }
  else
  {
    if (hSubClass=AkelPad.WindowSubClass(2 /*WSC_EDITPROC*/, EditCallback, 0x020A /*WM_MOUSEWHEEL*/))
    {
      //Allow other scripts running.
      AkelPad.ScriptNoMutex();

      //Message loop.
      AkelPad.WindowGetMessage();

      AkelPad.WindowUnsubClass(2 /*WSC_EDITPROC*/);
    }
  }

  function EditCallback(hWnd, uMsg, wParam, lParam)
  {
    if (uMsg == 0x020A /*WM_MOUSEWHEEL*/)
    {
      if ((wParam & 0xffff) == 0x8 /*MK_CONTROL*/)
      {
        AkelPad.WindowNoNextProc(hSubClass);
        return 0;
      }
    }
  }


_TCHAR
______

Constant that determines the end of system functions. Uses for AkelPad.SystemFunction().Call method.

  _TCHAR

Return Value
  String. "A" - functions calls with "A" ending (Windows 95/98/Me).
          "W" - functions calls with "W" ending (Windows NT/2000/XP).

Example:
  //How to provide support for Unicode and not lose compatibility with Win9x:
  var oSys=AkelPad.SystemFunction();
  var lpBuffer;
  var pWinDir;

  if (lpBuffer=AkelPad.MemAlloc(256 * _TSIZE))
  {
    oSys.Call("kernel32::GetWindowsDirectory" + _TCHAR, lpBuffer, 256);
    pWinDir=AkelPad.MemRead(lpBuffer, _TSTR);

    AkelPad.MemFree(lpBuffer);
  }


_TSTR
_____

Constant that determines the string type. Uses for MemCopy and MemRead methods.

  _TSTR

Return Value
  Number. 0 - DT_ANSI - ansi string (Windows 95/98/Me).
          1 - DT_UNICODE - unicode string (Windows NT/2000/XP).

Example:
  See _TCHAR example.


_TSIZE
______

Constant that determines the size of symbol in bytes. Uses for MemAlloc method.

  _TSIZE

Return Value
  Number. 1 - sizeof(char) - one byte (Windows 95/98/Me).
          2 - sizeof(wchar_t) - two bytes (Windows NT/2000/XP).

Example:
  See _TCHAR example.


_X64
____

Constant that determines the program bits type - x86 or x64.

  _X64

Return Value
  Number. 0 - x86 version.
          1 - x64 version.

Example:
  if (_X64)
    WScript.Echo("x64 version");
  else
    WScript.Echo("x86 version");


*** ActiveX ***

Scripts.dll can be used in third party applications after library registration.
- x86 version registration: regsvr32.exe Scripts.dll
- x64 version registration: "%SystemRoot%\System32\regsvr32.exe" Scripts.dll

Usage example:
  var AkelPad=new ActiveXObject("AkelPad.Document");
  var _TCHAR=AkelPad.Constants._TCHAR;
  var _TSTR=AkelPad.Constants._TSTR;
  var _TSIZE=AkelPad.Constants._TSIZE;
  var _X64=AkelPad.Constants._X64;

  var oSys=AkelPad.SystemFunction();
  var lpBuffer;
  var pWinDir="";

  if (lpBuffer=AkelPad.MemAlloc(256 * _TSIZE))
  {
    oSys.Call("kernel32::GetWindowsDirectory" + _TCHAR, lpBuffer, 256);
    pWinDir=AkelPad.MemRead(lpBuffer, _TSTR);

    AkelPad.MemFree(lpBuffer);
  }
  WScript.Echo(pWinDir);
